var app = angular.module('app');
app.controller('fileUploadModalCtrl', ['$scope', '$modalInstance', '$timeout', 'uploadFileService',
    function ($scope, $modalInstance, $timeout, uploadFileService) {
        $scope.isReady = false;
        $scope.images = [];
        // file upload
        $scope.uploadFile = function (file, errFiles) {
            $scope.picFile = file;
            $scope.errFile = errFiles && errFiles[0];
            if (file) {
                uploadFileService.uploadFile(file, errFiles).then(function (data) {
                    $scope.isReady = true;
                    $scope.picUrl = data.url;
                    $scope.uploadErrMsg = null;
                }, function (err) {
                    $scope.uploadErrMsg = '图片上传失败,请重新选择文件';
                });
            }
        };
        $scope.ok = function () {
            $modalInstance.close($scope.picUrl);
        };
        $scope.cancel = function () {
            $modalInstance.dismiss();
        };

    }]);